/*
 * Copyright (C) 2019 xuexiangjys(xuexiangjys@163.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package com.xuexiang.templateproject.fragment.favorite;


//import static com.xuexiang.xutil.XUtil.runOnUiThread;


import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.recyclerview.widget.DividerItemDecoration;
import androidx.recyclerview.widget.LinearLayoutManager;


import com.xuexiang.templateproject.R;
import com.xuexiang.templateproject.activity.CameraViewActivity;
//import com.xuexiang.templateproject.activity.MatchActivity;
import com.xuexiang.templateproject.adapter.FavoriteItemAdapter;
//import com.xuexiang.templateproject.adapter.ImageItemAdapter;

import com.xuexiang.templateproject.bean.QuestionBean;
import com.xuexiang.templateproject.core.BaseFragment;
import com.xuexiang.templateproject.databinding.FragmentFavoriteBinding;
import com.xuexiang.templateproject.utils.DbUtils;
import com.xuexiang.templateproject.widget.showLoadingDialog;
import com.xuexiang.xaop.annotation.SingleClick;
import com.xuexiang.xpage.annotation.Page;
import com.xuexiang.xui.widget.actionbar.TitleBar;
//import com.xuexiang.xutil.common.logger.Logger;

import java.util.List;

/**
 * @author xuexiang
 * @since 2019-10-16 10:25
 */
@Page(name = "收藏", extra = R.drawable.ic_expand_camera)
public class FavoriteFragment extends BaseFragment<FragmentFavoriteBinding> implements View.OnClickListener{

    @Override
    protected FragmentFavoriteBinding viewBindingInflate(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, boolean attachToRoot) {
        return FragmentFavoriteBinding.inflate(inflater, container, attachToRoot);
    }
//    @Override
//    protected TitleBar initTitle() {
//        return null;
//    }

    @Override
    protected void initViews() {
        List<QuestionBean> questionBeanList =DbUtils.getInstance().getQuestionHistory();

        FavoriteItemAdapter favoriteItemAdapter = new FavoriteItemAdapter(questionBeanList);

        favoriteItemAdapter.setOnItemClickListener((adapter, view, position) -> {
            long id = ((FavoriteItemAdapter)adapter).getItem(position).getId();
//            String imgOss = ((FavoriteItemAdapter)adapter).getItem(position).getImageOss();
//            Logger.d("setOnItemChildClickListener "+imgOss);
//            showLoadingDialog.showLoading(getContext());
//            MatchActivity.open(getActivity(),imgPath,"");
            Bundle params = new Bundle();
            params.putLong("id",id);
            openPage(FavoriteDetailFragment.class,params);

        });
        binding.recyclerview.setLayoutManager(new LinearLayoutManager(getContext()));
        binding.recyclerview.setAdapter(favoriteItemAdapter);
        binding.recyclerview.addItemDecoration(new DividerItemDecoration(getContext(), LinearLayoutManager.VERTICAL));

    }


    @SingleClick
    @Override
    public void onClick(View view) {

    }


}
